package chinatelecom.feilong.framework.web.sys.util;

import chinatelecom.feilong.framework.web.sys.entity.SysUser;
import com.alibaba.fastjson.JSONObject;
import org.apache.shiro.SecurityUtils;

/**
 * 
* @Description: 用户工具类
* @author JRed bravecatking@gmail.com 
* @date 2015年11月8日 下午2:41:04
 */
public class UserUtils {
	
	/**
	 * 
	* @Title: getCurrentUser 
	* @Description: 获取当前登录用户
	* @author JRed bravecatking@gmail.com   
	* @param @return
	* @return SysUser
	* @throws
	 */
	public static SysUser getCurrentUser(){
		org.apache.shiro.subject.Subject subject = SecurityUtils.getSubject();
	    SysUser currentUser = (SysUser)subject.getPrincipal();
	    return currentUser;
	}

	/**
	 * 拷贝数据到用户
	 * @param jsonObject
	 * @return
	 */
	public static SysUser copyToUser(JSONObject jsonObject){
		SysUser user = new SysUser();
		user.setId(jsonObject.getInteger("id"));
		user.setUsername(jsonObject.getString("userName"));
		user.setRealname(jsonObject.getString("realName"));
		user.setUserType(jsonObject.getInteger("userType"));
		user.setEmail(jsonObject.getString("email"));
		user.setGender(jsonObject.getString("gender"));
		user.setiDcard(jsonObject.getString("idCard"));
		user.setMobile(jsonObject.getString("mobile"));
		user.setStatus(jsonObject.getInteger("status"));
		return user;

	}

}
